import app from "../../../../app";
import { player, wallet_key } from "../../../../model/fight/body/player";
import { Tpl_guess, template } from "../../../../shared/master/MsgAction";
import manage_user from "../../../model/manage/manage_user";

class guess {
    /**
     * 第多少回合
     */
    round: number = 0;
    succress: number = 0;
    min: number = 1;
    max: number = 100;
    gold: number = 1000;
    private cont:number = 0;
    constructor() {
        this.nextRound()
    }
    nextRound() {
        this.round += 1;
        this.min = 1;
        this.max = 10001;
        this.succress = app.random(this.min, this.max)
        this.gold = 1000;
        this.cont = 0;
    }
    guess(p: player, num: number) {
        let res = p.check_wallet(100, 0, [], false, '澳门·多人猜数', true);
        if (!res.state) {
            return;
        }
        if (num == this.succress) {
            // 猜对了
            console.log('猜对了')
            p.wallet_change(wallet_key.gold, this.gold)
            p.sendMsg(template.default_none,`🎉恭喜你！在魔改猜数第${this.round}轮中获得💰${this.gold}!`)
            manage_user.sendAllMsg(template.default_none,`🎉恭喜${p.nickName}！在魔改猜数第${this.round}轮中获得💰${this.gold}!`)
            this.nextRound();
            return;
        }
        if(num > this.succress && this.max > num){
            this.max = num;
        }
        if(num < this.succress){
            this.min = num;
        }
        if (this.min > 1) {
            this.min -= app.generateRandom(1, this.min - 1, 0, 10);
        }
        this.gold += app.random(20,120)
        this.max += app.random(1, 10);
        this.succress = app.random(this.min, this.max)
        this.cont += 1;

        p.sendMsg(template.default_none,`😭很遗憾,你没有猜中`)
        this.look(p);
    }
    look(p: player) {
        let tpl:Tpl_guess =  {
            round: this.round,
            min: this.min,
            max: this.max,
            gold: this.gold,
            cont: this.cont
        }
        p.sendMsg(template.猜数信息,tpl)

    }
}
export default new guess();